﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;


namespace IHISCETeim.DAL
{
    /// <summary>
    /// 5.机器维保费收入记录(FTradeUpKeep)
    /// </summary>
    public　class FTradeUpKeepDAL
    {
        public static int Add(FTradeUpKeepInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeUpKeep_Add", obj.FTradeID, obj.Title, obj.JinE, obj.InputDate, obj.RealName,obj.Remark,obj.JinE2);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(int id)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeUpKeep_Delete", id);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetAllByFTradeID(int FTradeID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeUpKeep_GetAllByFTradeID", FTradeID);
            return DB.ExecuteReader(dbCommand);
        }

        public static IDataReader GetById(int ID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeUpKeep_GetById", ID);
            return DB.ExecuteReader(dbCommand);
        }

        public static bool Update(FTradeUpKeepInfo obj)
        {
            try
            {
                Database DB = DatabaseFactory.CreateDatabase();

                DbCommand dbCommand = DB.GetStoredProcCommand("FTradeUpKeep_Update", obj.id, obj.Title, obj.JinE, obj.InputDate, obj.RealName, obj.Remark, obj.JinE2);
                 DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch {
                return false;
            }
        }

    }
}
